package com.gucheng;

import java.util.Scanner;

/**
 * quickselect（快选）
 */
public class QuickselectMain {

    static int N = 100010, n, k;
    static int[] w = new int[N];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        k = in.nextInt();
        for (int i = 0; i < n; i++) {
            w[i] = in.nextInt();
        }
        System.out.println(QuickSelect(0, n - 1, k));
    }

    private static int QuickSelect(int l, int r, int k) {
        if (l >= r) return w[l];
        //i为左边界，j为右边界，x为基准
        int i = l - 1, j = r + 1, x = w[l + r >> 1];
        while (i < j) {
            while (w[++i] < x) ;
            while (w[--j] > x) ;
            if (i < j) {
                int t = w[i];
                w[i] = w[j];
                w[j] = t;
            }
        }
        //判断基准的位置
        int sl = j - l + 1;
        //如果基准位置大于k，则递归左半部分
        if (sl >= k) return QuickSelect(l, j, k);
        //如果基准位置小于k，则递归右半部分
        return QuickSelect(j + 1, r, k - sl);
    }
}
